'''负责传感器信号的获取和循迹模块的信号获取与判断运动'''
from pyb import Pin
from pyb import delay
from pyb import UART

minipyb1=UART(1,9600)#TX:B6、RX:B7

'''左面5路循迹传感器定义'''
LeftSensorPins = ['X1','X2', 'X3','X4','X5']#
LeftSensor= [Pin(Pin(pin), Pin.IN) for pin in LeftSensorPins]
def LeftSensorCheck():
    return [LeftSensor[p].value() for p in range(len(LeftSensorPins))]

'''右面10路循迹传感器定义'''
RightSensorPins = ['X6','X7', 'X8','Y11','Y12','Y5','Y6', 'Y7','Y8','Z1']#
RightSensor= [Pin(Pin(pin), Pin.IN) for pin in RightSensorPins]
def RightSensorCheck():
    return [RightSensor[p].value() for p in range(len(RightSensorPins))]

def SlowStop():#通过左面循迹模块判断是否减速或停止，停止即到达物料区
    Left=LeftSensorCheck()
    if Left==[1,1,1,1,0] or Left==[1,1,1,0,0] or Left==[1,1,0,0,0]:
        return 's'#Slow
    elif Left==[1,0,0,0,0] or Left==[0,0,0,0,0]:
        return 'c'
    else:
        return 'f'
def RunMain():
    while 1:
        if minipyb1.any():
            command=minipyb1.read(1)
            print(command)
            if command.find(b'l')>-1:
                text=LeftSensorCheck()
                print(text)
                minipyb1.write(str(text))
            elif command.find(b'r')>-1:
                print(text)
                text=RightSensorCheck()
                minipyb1.write(str(text))

